package com.scm.servlet.pomain;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.scm.dao.PoitemDao;
import com.scm.dao.PomainDao;
import com.scm.model.Poitem;
import com.scm.model.Pomain;

/**
 * Servlet implementation class QueryPomainDetailServlet
 */
@WebServlet("/main/pomain/QueryPomainDetail")
public class QueryPomainDetailServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}


	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String poId = req.getParameter("poId");
		PomainDao pomaindao = new PomainDao();
		PoitemDao poitemdao = new PoitemDao();
		Pomain pomain = new Pomain();
		List<Poitem> poitems = new ArrayList<Poitem>();
		try {
			pomain = pomaindao.queryPomainByPoId(Long.parseLong(poId));
			poitems = poitemdao.selectByPoid(Long.parseLong(poId));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		req.setAttribute("pomain", pomain);
		req.setAttribute("poitems", poitems);
		req.getRequestDispatcher("/gztm/pomain_change.jsp").forward(req, resp);
	}

}
